package com.tianjian.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.tianjia.entity.Sheji;
import com.tianjia.uitl.DBManager;

public class SheJiDaoImpl {
	public List<Sheji> getShejiList() {
		List<Sheji> list = new ArrayList<Sheji>();//创建设计师集合
		Connection conn = DBManager.getConnection();//创建连接
		//全局变量
		Statement st = null;
		ResultSet rs = null;
		
		try {//正常执行
			//创建Statement执行对象,作用是执行sql语句
			st = conn.createStatement();
			//执行sql语句
			rs = st.executeQuery("select * from sheji");
			//遍历结果集
			while(rs.next()) {
				int sheJiShiId = rs.getInt("sheJiShiId");
				String zhaoPian = rs.getString("zhaoPian");
				String sheJiShiName = rs.getString("sheJiShiName");
				String zhiWei = rs.getString("zhiWei");
				//创建sheji对象
				Sheji sheji = new Sheji(sheJiShiId,zhaoPian,sheJiShiName,zhiWei);
				list.add(sheji);//把sheji对象添加到list中
			}
			return list;//正常返回list
		} catch (SQLException e) {//异常执行
			e.printStackTrace();
			return null;//异常情况下返回null
		}finally {//关闭流
			DBManager.closeAll(conn, st, rs);
		}
	}
}
